﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;


/// <summary>
/// Node 的摘要说明
/// </summary>
public class Node
{
    private int id;
    /// <summary>
    /// 根节点为0
    /// </summary>
    private int pid = 0;
    private string name;
    /// <summary>
    /// 层级
    /// </summary>
    private int level;
    /// <summary>
    /// 是否展开
    /// </summary>
    private bool isExpand = false;
    private string icon;

    private Node parent;
    private List<Node> children = new List<Node>();
    
    public Node()
    {
        //
        // TODO: 在此处添加构造函数逻辑
        //
    }
    public Node(int id,int pid,string name)
    {
        this.id = id;
        this.pid = pid;
        this.name = name;
    }

    public int Id { get; set; }
    public int Pid { get; set; }
    public string Name { get; set; }
    /// <summary>
    /// 计算当前节点的层级
    /// </summary>
    /// <returns></returns>
    public int Level
    {
        get
        {
            return parent == null ? 0 : parent.Level + 1;
        }
        set
        {
            this.level = value;
        }
    }
    public bool IsExpand
    {
        get
        {
            return isExpand;
        }
        set
        {
            if (!isExpand)
            {
                foreach(Node node in children)
                {
                    node.isExpand = false;
                }
            }
        }
    }
    public string Icon { get; set; }
    public Node Parent { get; set; }
    public List<Node> Children { get; set; }


    public bool isRoot()
    {
        return parent == null;
    }
    /// <summary>
    /// 判断父节点是否是收缩状态
    /// </summary>
    /// <returns></returns>
    public bool isParentExpand()
    {
        if (parent == null) return false;
        return parent.isExpand;
    }
    /// <summary>
    /// 是否叶子节点
    /// </summary>
    /// <returns></returns>
    public bool isLeaf()
    {
        return children.Count() == 0;
    }



}